import java.util.Scanner;

public class ces2 {
    public static void main(String[] args) {

        System.out.println("1.复数");
        System.out.println("2.非复数");
        System.out.println("请选择你输入第1个数字类型：");
        Complex complex1 = new Complex();
        Complex complex2 = new Complex();
        Scanner scanner = new Scanner(System.in);
        int key1 = scanner.nextInt();
        if (key1 == 1) {
            System.out.println("请先输入实部：");
            double m = scanner.nextDouble();
            System.out.println("请输入虚部：");
            double n = scanner.nextDouble();
            complex1.real = m;
            complex1.imaginary = n;
        }else{
            System.out.println("请先输入数字：");
            double y = scanner.nextDouble();
            complex1.real = y;
            complex1.imaginary = 0;
        }
        System.out.println();
        System.out.println("*************************************");
        System.out.println();
        System.out.println("1.复数");
        System.out.println("2.非复数");
        System.out.println("请选择你输入第2个数字类型：");

        int key2 = scanner.nextInt();
        if (key2 == 1) {
            System.out.println("请先输入实部：");
            double a = scanner.nextDouble();
            System.out.println("请输入虚部：");
            double b = scanner.nextDouble();
            complex2.real = a;
            complex2.imaginary = b;
        }else{
            System.out.println("请先输入数字：");
            double x = scanner.nextDouble();
            complex2.real = x;
            complex2.imaginary = 0;
        }
        Complex complex = new Complex();
        complex.real = complex1.real + complex2.real;
        complex.imaginary = complex1.imaginary + complex2.imaginary;
        System.out.println();
        System.out.println("两数相加结果为：");
        complex.print();
    }
}
class Complex2{
    public double real;
    public double imaginary;
    public void print()
    {
        if(this.imaginary<0)//当复数的虚部为负数时，避免多打印出一个"+"
        {
            System.out.println(this.real+""+this.imaginary+"i");
        } else if (this.imaginary ==0) {
            System.out.println(this.real);
        } else {
            System.out.println(this.real+"+"+this.imaginary+"i");
        }
    }
}